<template>
	<view class="home-page">
		<u-navbar title="商品详情" bgColor="rgba(255,255,255,0.0)" :autoBack="true">
		</u-navbar>
		<view class="top-content">
			<view style="height: 50rpx;"></view>
			<view class="top-image">
				<image :src="info.goodsImgs" mode=""></image>
			</view>
		</view>
		<view class="content">
			<view class="goods-name">
				{{info.goodsName}}
			</view>
			<view class="goods-info">
				<view class="info-left">
					<view class="price">
						￥<text>{{info.currentPrice}}</text>
					</view>
					<view class="del-price">
						￥{{info.originalPrice}}
					</view>
				</view>
				<view class="info-right">
					<image src="../../../static/home/vip.png" mode=""></image>
					<view class="brief">
						好品质 放心批
					</view>
				</view>
			</view>
			<view class="goods-info">
				<view class="info-left">
					<image src="../../../static/home/hot.png" mode=""></image>
					<view>
						{{info.recommendationReason}}
					</view>
				</view>
				<view class="num">
					已售出{{info.quantitySold}}件
				</view>
			</view>
			<view class="goods-title">
				<view class="line"></view>
				<view>
					商品介绍
				</view>
			</view>
			<view class="goods-text">
				{{info.goodsDescription}}
			</view>
			<view class="top-content">
				<view style="height: 50rpx;"></view>
				<view class="top-image">
					<image :src="info.goodsImgs" mode=""></image>
				</view>
			</view>
		</view>
		<view style="height: 120rpx;"></view>
		<view class="btn">
			<u-button @click="gobuy" color="linear-gradient( 90deg, #FE8A03 0%, #FA5900 100%)" size="large"
				type="primary" text="申请货量"></u-button>
		</view>
		<u-popup :show="show" @close="close" round="10" mode="center">
			<view class="popup">
				<view class="popup-title">请输入接单金额范围</view>
				<view class="title">
					最小金额
				</view>
				<view class="text">
					<u-input placeholder="最小金额" type="number" border="none" v-model="minpirce">
					</u-input>
				</view>
				<view class="title">
					最大金额
				</view>
				<view class="text">
					<u-input placeholder="最大金额" type="number" border="none" v-model="maxpirce">
					</u-input>
				</view> 
				<view class="popup-btn">
					<u-button type="primary" text="确定" @click="goquer"
						color="linear-gradient(90deg, #FE8A03 0%, #FA5900 100%)"></u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				info: {},
				Takinginfo:{},
				id: '',
				minpirce:'',
				maxpirce:''
			}
		},
		onLoad(e) {
			this.id = e.id
			this.getdetail(e.id)
			this.getTaking()
		},
		methods: {
			getTaking() {
				this.$Request({
					method: 'GET',
					url: '/api/goods/taking/getTaking',
					data: {},
					ismsg: false,
				}).then(res => {
					console.log(res)
					if (res.code == 200) {
						this.Takinginfo = res.data
						if(res.data.minAmount!=null){
							this.minpirce = res.data.minAmount
						}
						if(res.data.minAmount!=null){
							this.maxpirce = res.data.maxAmount
						}
					}
				})
			},
			goquer() {
				if(this.Takinginfo.isOpen == 0){
					if (this.minpirce == '') {
						uni.showToast({
							title: '请输入最小金额！',
							icon: 'none'
						})
						return
					}
					if (this.maxpirce == '') {
						uni.showToast({
							title: '请输入最大金额！',
							icon: 'none'
						})
						return
					}
					if (this.minpirce >= this.maxpirce) {
						uni.showToast({
							title: '最小金额不可等于或高于最大金额！',
							icon: 'none'
						})
						return
					}
					let params = {
						minAmount: this.minpirce,
						maxAmount: this.maxpirce
					}
					uni.showLoading({
						mask: true
					})
					this.$Request({
						method: 'POST',
						url: '/api/goods/taking/openTaking',
						data: params,
						ismsg: false,
					}).then(res => {
						uni.hideLoading()
						if (res.code == 200) {
							this.show = false
							uni.showToast({
								title:'开始批货',
								icon:'none'
							})
							setTimeout(()=>{
								uni.reLaunch({
									url:'/pages/purchasing/index'
								})
							},500)
						}else{
							if(res.msg == '银行卡'){
								this.show = false
								uni.showToast({
									title:'请绑定银行卡账户！',
									icon:'none'
								})
								setTimeout(()=>{
									uni.navigateTo({
										url: '/pages/my/account/receive/list?type='+ 3
									})
								},500)
								return
							}
							if(res.msg == '微信'){
								this.show = false
								uni.showToast({
									title:'请绑定微信账户！',
									icon:'none'
								})
								setTimeout(()=>{
									uni.navigateTo({
										url: '/pages/my/account/receive/list?type='+ 2
									})
								},500)
								return
							}
							if(res.msg == '支付宝'){
								this.show = false
								uni.showToast({
									title:'请绑定支付宝账户！',
									icon:'none'
								})
								setTimeout(()=>{
									uni.navigateTo({
										url: '/pages/my/account/receive/list?type='+ 1
									})
								},500)
								return
							}
						}
					})
				}else{
					this.show = false
					uni.showToast({
						title:'您已开启批货！',
						icon:'none'
					})
					setTimeout(()=>{
						uni.reLaunch({
							url:'/pages/purchasing/index'
						})
					},500)
				}
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						uni.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			close() {
				this.show = false
			},
			gobuy() {
				this.show = true
			},
			getdetail(id) {
				let params = {
					id: id
				}
				this.$Request({
					method: 'GET',
					url: '/api/goods/info/detail',
					data: params,
					ismsg: false,
				}).then(res => {
					if (res.code == 200) {
						this.info = res.data
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.home-page {
		.popup {
			width: 520rpx;
			padding: 30rpx;

			.popup-title {
				text-align: center;
				font-weight: 900;
				font-size: 32rpx;
			}

			.popup-btn {
				margin-top: 50rpx;
			}

			.title {
				font-size: 28rpx;
				color: #333333;
				font-weight: bold;
				margin-top: 20rpx;
			}

			.text {
				background-color: #ffffff;
				box-shadow: 0rpx 0rpx 16rpx 1rpx rgba(0, 0, 0, 0.08);
				padding: 20rpx 30rpx;
				margin-top: 20rpx;
				border-radius: 20rpx;
			}
		}

		.btn {
			width: 93%;
			position: fixed;
			bottom: 30rpx;
			left: 0;
			right: 0;
			border-radius: 20rpx;
			overflow: hidden;
			margin: 0 auto;
		}

		.top-content {
			background-color: #ffe4df;

			.top-image {
				display: flex;
				justify-content: center;
				align-items: center;

				image {
					width: 500rpx;
					height: 500rpx;
				}
			}
		}

		.content {
			background-color: #ffffff;
			padding: 30rpx;

			.goods-name {
				color: #333333;
				font-size: 36rpx;
				font-weight: bold;
			}

			.goods-info {
				padding-bottom: 25rpx;
				border-bottom: 1rpx solid #E2E2E2;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 30rpx;

				.info-left {
					display: flex;
					align-items: center;
					color: #333333;

					.price {
						font-size: 24rpx;
						color: #FB6500;
						font-weight: bold;

						text {
							font-size: 48rpx;
						}
					}

					image {
						width: 32rpx;
						height: 32rpx;
						margin-right: 10rpx;
					}

					.del-price {
						font-size: 32rpx;
						color: #999999;
						text-decoration-line: line-through;
						margin-left: 20rpx;
					}
				}

				.info-right {
					display: flex;
					align-items: center;
					font-size: 24rpx;

					image {
						width: 22rpx;
						height: 20rpx;
					}

					.brief {
						color: #FB9F00;
						margin-left: 20rpx;
					}
				}

				.num {
					font-size: 24rpx;
					color: #999999;
				}
			}

			.goods-title {
				font-size: 28rpx;
				color: #333333;
				font-weight: bold;
				display: flex;
				align-items: center;
				margin-top: 30rpx;

				.line {
					width: 6rpx;
					height: 30rpx;
					background-color: #FB6500;
					margin-right: 10rpx;
				}
			}

			.goods-text {
				margin: 20rpx 0;
				font-size: 28rpx;
				color: #666666;
			}
		}
	}
</style>